package com.jh.fcsm.controller.sys.rest;

import com.jh.fcsm.beans.sys.SysDictItem;
import com.jh.fcsm.common.BaseController;
import com.jh.fcsm.service.sys.SysDictItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 可匿名访问的字典接口
 */
@RestController
@RequestMapping("/sys/dict/rest")
@Api(value = "字典REST", tags = "字典RESTAPI")
public class RestSysDictItemController extends BaseController {

    @Autowired
    private SysDictItemService basicDictItemService;

    /**
     * 根据字典CODE得到下级结点列表一级
     *
     * @param typeCode 字典编码
     * @return 子节点数据
     */
    @GetMapping("/findDictItemByDictType")
    @ApiOperation(value = "根据字典类型获取字典条目", notes = "根据字典类型获取字典条目")
    public List<SysDictItem> findDictItemByDictType(@RequestParam(value = "typeCode", required = true) String typeCode) {
        return basicDictItemService.findDictItemByDictCode(typeCode);
    }

    /**
     * 根据字典编码获取字典
     *
     * @param code 字典编码
     * @return 字典信息
     */
    @GetMapping("/findDictItem")
    @ApiOperation(value = "根据字典条目 code 得到值", notes = "根据字典条目 code 得到值")
    public SysDictItem findDictItem(@RequestParam(value = "code", required = true) String code) {
        return basicDictItemService.findDictByCode(code);
    }
}
